home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DartmouthXCMDs.cpt / Dartmouth XCMDs Vol 1&2 / card_2102.txt < prev    next >
Text File  |  1989-02-26  |  11KB  |  376 lines

  1. -- card: 2102 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 3241
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (button)
  9. -- low flags: 00
  10. -- high flags: A003
  11. -- rect: left=65 top=279 right=301 bottom=200
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 1
  15. -- font id: 0
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: until mouse press
  20. ----- HyperTalk script -----
  21. on mouseUp
  22.   PopUpPicture 1508,50,54,3,false
  23. end mouseUp
  24.  
  25.  
  26.  
  27. -- part 2 (button)
  28. -- low flags: 00
  29. -- high flags: A003
  30. -- rect: left=65 top=302 right=323 bottom=201
  31. -- title width / last selected line: 0
  32. -- icon id / first selected line: 0 / 0
  33. -- text alignment: 1
  34. -- font id: 0
  35. -- text size: 12
  36. -- style flags: 0
  37. -- line height: 16
  38. -- part name: until mouse release
  39. ----- HyperTalk script -----
  40. on mouseDown
  41.   PopUpPicture 20377,245,54,2,true
  42. end mouseDown
  43.  
  44.  
  45.  
  46. -- part 5 (field)
  47. -- low flags: 80
  48. -- high flags: 2007
  49. -- rect: left=12 top=26 right=298 bottom=491
  50. -- title width / last selected line: 0
  51. -- icon id / first selected line: 0 / 0
  52. -- text alignment: 0
  53. -- font id: 22
  54. -- text size: 10
  55. -- style flags: 0
  56. -- line height: 13
  57. -- part name: 
  58.  
  59.  
  60. -- part 6 (button)
  61. -- low flags: 00
  62. -- high flags: A003
  63. -- rect: left=314 top=300 right=322 bottom=435
  64. -- title width / last selected line: 0
  65. -- icon id / first selected line: 0 / 0
  66. -- text alignment: 1
  67. -- font id: 0
  68. -- text size: 12
  69. -- style flags: 0
  70. -- line height: 16
  71. -- part name: Show LSP Source
  72. ----- HyperTalk script -----
  73. on mouseUp
  74.   set the visible of card field 1 to not the visible of card field 1
  75.   if the visible of card field 1 is true then
  76.     set the name of me to "Hide LSP Source"
  77.   else set the name of me to "Show LSP Source"
  78. end mouseUp
  79.  
  80.  
  81.  
  82. -- part contents for background part 16
  83. ----- text -----
  84. POPUPPICTURE XCMD version 1.1
  85. Kevin Calhoun
  86.  
  87. PopUpPicture opens a window on top of the current card and displays a picture in it.  You can't do anything with the picture except look at it.  When you click the mouse (or, alternatively, when you release the mouse) the picture goes away and its window is disposed of.  Color pictures (in PICT2 format) will appear in color on a suitably equipped Mac II and will appear in monochrome on any other machine running System 4.1 or later.
  88. horse*
  89. You tell PopUpPicture what picture to draw by specifying the ID number a resource of type PICT, which can be contained in the current stack or in any other open resource file, including the home stack, HyperCard, or the System file.  Any picture you've copied to the clipboard can become a resource of type PICT--use the ClipToPICT XFCN to achieve this transformation and to install the new PICT resource in your stack.  A file of type PICT can be converted to a PICT resource using the PICTFileToRes XFCN.
  90.  
  91. INVOKING POPUPPICTURE
  92.  
  93. PopUpPicture takes six parameters, the last two of which are optional.  You must specify the ID of the PICT resource you want displayed, the horizontal and vertical coordinates of the top left corner of the window in which the picture will be drawn, and the type of window you want.  You may also specify that you want the picture to disappear when the mouse button is next released rather than when it is next pushed.
  94.  
  95. The format of a PopUpPicture call is:
  96.  
  97. PopUpPicture   pictureID, top, left, windowKind, ¬´onMouseUp¬ª,¬´passThru¬ª
  98.  
  99. The pictureID is the ID of the PICT resource you want displayed.
  100.  
  101. The top and left parameters are given as coordinates in the card window coordinate system.  A top of 0 and a left of 0 would draw the picture flush against the top left corner of the card window.
  102.  
  103. PopUpPicture will draw three different kinds of windows--a windowKind of 1 produces a modal dialog box (a box with a double border), a windowKind of 2 produces a plain box, and a windowKind of 3 produces a plain box with shadow.  If windowKind has any other value, PopUpPicture defaults to a plain box with shadow.  (Note that the top left corner of the picture will appear in the same place regardless of which windowKind you request, although the top left corner of the window will vary.) 
  104.  
  105. If you want the picture to remain present until the next time the user pushes the mouse button, pass "false" in the onMouseUp parameter.  If you want the picture to remain present until the next time the user releases the mouse button, pass "true" in the onMouseUp parameter.  If you don't provide the onMouseUp parameter, PopUpPicture will remove the picture on the next push of the mouse button.  
  106.  
  107. The event that causes the picture to be removed, a mouseDown if onMouseUp is FALSE, a mouseUp if onMouseUp is TRUE, can be passed on to HyperCard.  If you want the event to be passed on so that it generates a HyperTalk message, pass "true" in the passThru parameter.  To test this effect, add the passThru parameter to the script of the button "until mouse press."
  108.  
  109. EXAMPLES:
  110.  
  111. PopUpPicture 14990,40,56,3,false
  112. PopUpPicture 14990,19,34,2,true
  113.  
  114. REVISION HISTORY
  115. 1.0 -- 4/22/88
  116. 1.1 -- 7/7/88 -- added passThru option
  117.  
  118.  
  119. -- part contents for card part 5
  120. ----- text -----
  121. UNIT PopUpPicture;
  122. { PopUpPicture XCMD ¬©1988 by the Trustees of Dartmouth College. }
  123. { Written by John K. Calhoun, Courseware Development. }
  124.  
  125. INTERFACE
  126.  USES
  127.   XCMDIntf, ColorQuickDraw, ColorWindowMgr;
  128.  TYPE
  129.   Str31 = STRING[31];
  130.  
  131.  
  132.  PROCEDURE Main (paramPtr : XCMDPtr);
  133.  
  134. IMPLEMENTATION
  135.  
  136.  
  137.  PROCEDURE DoJsr (addr : ProcPtr);
  138.  INLINE
  139.   $205F, $4E90;
  140.  
  141.  FUNCTION EvalExpr (paramPtr : XCmdPtr;
  142.          expr : Str255) : Handle;
  143.  BEGIN
  144.   WITH paramPtr^ DO
  145.    BEGIN
  146.     inArgs[1] := ORD(@expr);
  147.     request := xreqEvalExpr;
  148.     DoJsr(entryPoint);
  149.     EvalExpr := Handle(outArgs[1]);
  150.    END;
  151.  END;
  152.  
  153.  PROCEDURE ZeroToPas (paramPtr : XCmdPtr;
  154.          zeroStr : Ptr;
  155.          VAR pasStr : Str255);
  156.  BEGIN
  157.   WITH paramPtr^ DO
  158.    BEGIN
  159.     inArgs[1] := ORD(zeroStr);
  160.     inArgs[2] := ORD(@pasStr);
  161.     request := xreqZeroToPas;
  162.     DoJsr(entryPoint);
  163.    END;
  164.  END;
  165.  
  166.  FUNCTION StrToNum (paramPtr : XCmdPtr;
  167.          str : Str31) : LongInt;
  168.  BEGIN
  169.   WITH paramPtr^ DO
  170.    BEGIN
  171.     inArgs[1] := ORD(@str);
  172.     request := xreqStrToNum;
  173.     DoJsr(entryPoint);
  174.     StrToNum := outArgs[1];
  175.    END;
  176.  END;
  177.  
  178.  FUNCTION PasToZero (paramPtr : XCmdPtr;
  179.          str : Str255) : Handle;
  180.  BEGIN
  181.   WITH paramPtr^ DO
  182.    BEGIN
  183.     inArgs[1] := ORD(@str);
  184.     request := xreqPasToZero;
  185.     DoJsr(entryPoint);
  186.     PasToZero := Handle(outArgs[1]);
  187.    END;
  188.  END;
  189.  
  190.  FUNCTION StrToBool (paramPtr : XCmdPtr;
  191.          str : Str31) : BOOLEAN;
  192.  BEGIN
  193.   WITH paramPtr^ DO
  194.    BEGIN
  195.     inArgs[1] := ORD(@str);
  196.     request := xreqStrToBool;
  197.     DoJsr(entryPoint);
  198.     StrToBool := BOOLEAN(outArgs[1]);
  199.    END;
  200.  END;
  201.  
  202.  FUNCTION NumToStr (paramPtr : XCmdPtr;
  203.          num : LongInt) : Str31;
  204.   VAR
  205.    str : Str31;
  206.  BEGIN
  207.   WITH paramPtr^ DO
  208.    BEGIN
  209.     inArgs[1] := num;
  210.     inArgs[2] := ORD(@str);
  211.     request := xreqNumToStr;
  212.     DoJsr(entryPoint);
  213.     NumToStr := str;
  214.    END;
  215.  END;
  216.  
  217.  PROCEDURE SendCardMessage (paramPtr : XCmdPtr;
  218.          msg : Str255);
  219.  BEGIN
  220.   WITH paramPtr^ DO
  221.    BEGIN
  222.     inArgs[1] := ORD(@msg);
  223.     request := xreqSendCardMessage;
  224.     DoJsr(entryPoint);
  225.    END;
  226.  END;
  227.  
  228.  FUNCTION ColorQDExists : BOOLEAN;  { See tech note #119 }
  229.  
  230.   TYPE
  231.    WordPtr = ^Integer;
  232.   CONST
  233.    ROM85Loc = $28E;
  234.    TwoHighMask = $C000;
  235.   VAR
  236.    myWordPtr : WordPtr;
  237.  BEGIN
  238.   myWordPtr := WordPtr(ROM85Loc);
  239.   ColorQDExists := BitAnd(myWordPtr^, TwoHighMask) = 0;
  240.  END;
  241.  
  242.  FUNCTION GetLocOfCardWindow (paramPtr : XCmdPtr) : point;
  243.   VAR
  244.    theResult : Handle;
  245.    aString : Str255;
  246.    theLoc : point;
  247.  BEGIN
  248.   theResult := EvalExpr(paramPtr, 'item 1 of the loc of card window');
  249.   ZeroToPas(paramPtr, theResult^, aString);
  250.   DisposHandle(theResult);
  251.   theLoc.h := StrToNum(paramPtr, aString);
  252.  
  253.   theResult := EvalExpr(paramPtr, 'item 2 of the loc of card window');
  254.   ZeroToPas(paramPtr, theResult^, aString);
  255.   DisposHandle(theResult);
  256.   theLoc.v := StrToNum(paramPtr, aString);
  257.   GetLocOfCardWindow := theLoc;
  258.  END;
  259.  
  260.  PROCEDURE PopItUpAlready (paramPtr : XCMDPtr);
  261.   VAR
  262.    parameterCount : INTEGER;
  263.    pictID : INTEGER;
  264.    RTop : INTEGER;
  265.    RLeft : INTEGER;
  266.    windKind : INTEGER;
  267.    thePicHandle : PicHandle;
  268.    r : rect;
  269.    savePort : grafPtr;
  270.    myWindow : WindowPtr;
  271.    anEvent : EventRecord;
  272.    cardTopLeft : Point;
  273.    onRelease : boolean;
  274.    theMask : INTEGER;
  275.    passThru : BOOLEAN;
  276.  
  277.   PROCEDURE passReturnValue (theMsg : Str255); { set theResult and quit }
  278.   BEGIN
  279.    paramPtr^.returnValue := PasToZero(paramPtr, theMsg);
  280.   END;
  281.  
  282.   FUNCTION GetParameters (expected : INTEGER) : INTEGER;
  283.    VAR
  284.     count : INTEGER;
  285.     str : Str255;
  286.   BEGIN
  287.    count := paramPtr^.paramCount;
  288.    IF expected <= count THEN
  289.     BEGIN
  290.      GetParameters := count;
  291.      ZeroToPas(paramPtr, paramPtr^.params[1]^, str);
  292.      pictID := StrToNum(paramPtr, str);
  293.      ZeroToPas(paramPtr, paramPtr^.params[2]^, str);
  294.      RLeft := StrToNum(paramPtr, str);
  295.      ZeroToPas(paramPtr, paramPtr^.params[3]^, str);
  296.      RTop := StrToNum(paramPtr, str);
  297.      ZeroToPas(paramPtr, paramPtr^.params[4]^, str);
  298.      windKind := StrToNum(paramPtr, str);
  299.      IF count > 4 THEN
  300.       BEGIN
  301.        ZeroToPas(paramPtr, paramPtr^.params[5]^, str);
  302.        onRelease := StrToBool(paramPtr, str);
  303.        IF count > 5 THEN
  304.         BEGIN
  305.          ZeroToPas(paramPtr, paramPtr^.params[6]^, str);
  306.          passThru := StrToBool(paramPtr, str);
  307.         END;
  308.       END
  309.      ELSE
  310.       onRelease := FALSE;
  311.     END
  312.    ELSE
  313.     GetParameters := -1;
  314.   END;
  315.  
  316.  BEGIN
  317.   passThru := FALSE;
  318.   parameterCount := GetParameters(4);
  319.   IF parameterCount < 4 THEN
  320.    passReturnValue('PopUpPicture XCMD 1.1 -- July 7, 1988')
  321.   ELSE
  322.    BEGIN
  323.     thePicHandle := GetPicture(pictID);
  324.     IF thePicHandle <> NIL THEN
  325.      BEGIN
  326.       InitCursor;
  327.       r := thePicHandle^^.picFrame;                        {use actual size of picture}
  328.       cardTopLeft := GetLocOfCardWindow(paramPtr);
  329.       WITH r, cardTopLeft DO
  330.        offsetRect(r, -left + rLeft + h, -top + rTop + v);
  331.       getPort(savePort);  {save old port, create new window to fit pict, and prepare to draw there}
  332.       IF NOT (windKind IN [1..3]) THEN
  333.        windKind := altDBoxProc;
  334.       IF ColorQDExists THEN
  335.        myWindow := NewCWindow(NIL, r, '', TRUE, windKind, POINTER(-1), FALSE, 0)
  336.       ELSE
  337.        myWindow := NewWindow(NIL, r, '', TRUE, windKind, POINTER(-1), FALSE, 0); {wStorage}
  338.       setPort(myWindow);
  339.       ClipRect(myWindow^.PortRect);      {make sure clip region is not empty.  See Mac Tech Note #59.}
  340.  
  341.       {draw the pic into that window}
  342.       MoveHHi(Handle(thePicHandle));
  343.       HLock(handle(thePicHandle));
  344.       DrawPicture(thePicHandle, myWindow^.PortRect);    {draw picture, filling the window}
  345.  
  346.       { wait for mouse-down or mouse-up }
  347.       IF onRelease THEN
  348.        theMask := mupmask
  349.       ELSE
  350.        theMask := mdownMask;
  351.  
  352.       REPEAT
  353.        systemTask;
  354.       UNTIL OSEventAvail(theMask, anEvent);
  355.       IF NOT passThru THEN
  356.        IF GetNextEvent(theMask, anEvent) THEN
  357.         ;
  358.       {get rid of window and pict; restore port, and exit}
  359.       DisposeWindow(myWindow);
  360.       HUnlock(handle(thePicHandle));   {done with the picture here}
  361.       HPurge(Handle(thePicHandle));
  362.       setPort(savePort);
  363.      END
  364.     ELSE
  365.      passReturnValue(CONCAT('Error -- can''t find picture ID', numToStr(paramPtr, pictID), ' .'));
  366.  
  367.    END;
  368.   SendCardMessage(paramPtr, 'go to this card');
  369.  END;
  370.  
  371.  PROCEDURE Main;
  372.  BEGIN
  373.   PopItUpAlready(paramPtr);
  374.  END;
  375.  
  376. END.